package org.example;

import java.sql.*;

//查询操作
public class Jdbc_Teacher_CRUD_Search {
    public static void main(String[] args) {
        String url = "jdbc:mysql://localhost:3306/mysqlbase?serverTimezone=GMT&characterEncoding=utf8";
        String user = "root";
        String password = "1234";
        String sql = "SELECT * FROM teacher";
        try (Connection conn = DriverManager.getConnection(url, user, password);
             PreparedStatement ps = conn.prepareStatement(sql);){
            try (ResultSet resultSet = ps.executeQuery()) {
                while (resultSet.next()) {
                    System.out.println(resultSet.getObject(1)+" "+resultSet.getObject(2)+" "+resultSet.getObject(3)+" "+resultSet.getObject(4)  );
                }
            }catch (SQLException e) {
                e.printStackTrace();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
